class Admin::CategoriesController < Admin::BaseController

  def index
    @categories = Category.all
  end

  def new
    @category = Category.new
    @parents = Category.all
  end

  def edit
    @category = Category.find(params[:id])
    @parents = Category.all
  end

  def create
    @category = Category.new(params[:category])
    @parents = Category.all

    if @category.save
      flash[:notice] = 'Categorie is aangemaakt.'
      redirect_to admin_categories_path
    else
      render :action => "new"
    end

  end

  # PUT /categories/1
  # PUT /categories/1.xml
  def update
    @category = Category.find(params[:id])
    @parents = Category.all


    if @category.update_attributes(params[:category])
      flash[:notice] = 'Categorie is aangepast.'
      redirect_to admin_categories_path
    else
      render :action => "edit"
    end

  end

  # DELETE /categories/1
  # DELETE /categories/1.xml
  def destroy
    @category = Category.find(params[:id])
    @category.destroy

    redirect_to admin_categories_path
  end
end
